package com.mobileares.midp.widgets.client.page;

import com.google.gwt.user.client.ui.Widget;

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2010-12-3
 * Time: 14:48:19
 * To change this template use File | Settings | File Templates.
 */
public class WidgetFunctionManager {
    private static Set<WidgetFunction> cacheMap = new HashSet();

    public static void addWidgetFunction(WidgetFunction function) {
        cacheMap.add(function);
    }

    private static Widget getWidget(WidgetFunction function) {
        if (AccessHelper.isAccess(function, function))
            return function.getWidget();
        else
            return null;
    }

    /**
     * 根据 code id 获得对应的控件。
     * @param id
     * @return
     */
    public static Widget getWidget(String id) {
        for (WidgetFunction function : cacheMap) {
            if (id.equals(function.getCode())) {
                return getWidget(function);
            }
        }
        return null;
    }

}
